package com.sdkx.wear_os.adapter

import android.content.Context
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.DataBindingHolder
import com.sdkx.wear_os.R
import com.sdkx.wear_os.bean.DialogBean
import com.sdkx.wear_os.databinding.LayoutTvCenterBinding

/**
 * 弹窗适配器 不分页
 */
class DialogAdapter(isSingle: Boolean, isChangeColor: Boolean) :
    BaseQuickAdapter<DialogBean, DataBindingHolder<LayoutTvCenterBinding>>() {
    //是否单选
    private var isSingle = true

    //是否改变颜色
    private var isChangeColor = true

    init {
        this.isSingle = isSingle
        this.isChangeColor = isChangeColor
    }

    override fun onBindViewHolder(
        holder: DataBindingHolder<LayoutTvCenterBinding>,
        position: Int,
        item: DialogBean?
    ) {
        holder.binding.run {
            item?.let { item ->
                tv.text = item.content
                //灰色
                if (item.isGray) {
                    //选中且多选
                    if (item.isSelect && !isSingle) {
                        select.visibility = VISIBLE
                    } else {
                        select.visibility = GONE
                    }
                    tv.setTextColor(ContextCompat.getColor(context, R.color.gray_A3AAB2))
                } else {
                    //选中且改变颜色
                    if (item.isSelect && isChangeColor) {
                        tv.setTextColor(ContextCompat.getColor(context, R.color.teal_200))
                    } else {
                        tv.setTextColor(ContextCompat.getColor(context, R.color.black))
                    }
                    //选中且多选
                    if (item.isSelect && !isSingle) {
                        select.visibility = VISIBLE
                    } else {
                        select.visibility = GONE
                    }
                }
            }
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): DataBindingHolder<LayoutTvCenterBinding> {
        return DataBindingHolder<LayoutTvCenterBinding>(
            R.layout.layout_tv_center,
            parent
        )
    }
}